package com.black.cat.jvm.instructions.references;


import com.black.cat.jvm.instructions.base.InstructionNoOperands;
import com.black.cat.jvm.rtda.Frame;
import com.black.cat.jvm.rtda.JObject;
import com.black.cat.jvm.rtda.OperandStack;

//arraylength指令用于获取数组长度
public class ARRAY_LENGTH extends InstructionNoOperands {

    @Override
    public void execute(Frame frame) {

        OperandStack stack = frame.operandStack();
        JObject arrRef = stack.popRef();
        if (null == arrRef){
            throw new NullPointerException();
        }

        int arrLen = arrRef.arrayLength();
        stack.pushInt(arrLen);
    }

}
